using UnityEngine;
using UnityEngine.UI;
using Voodoo.Sauce.IAP;
using Voodoo.Sauce.Internal.Extension;

namespace Voodoo.Sauce.Debugger
{
	public class IAPProductWidget : Widget
	{
		[SerializeField]
		private GameObject _statusAvailable;

		[SerializeField]
		private GameObject _statusMissing;

		[SerializeField]
		private GameObject _statusBadID;

		[SerializeField]
		private GameObject _statusOwned;

		[SerializeField]
		private Text _productId;

		[SerializeField]
		private Text _details;

		[SerializeField]
		private Button _copyButton;

		[SerializeField]
		private Button _purchaseButton;

		private void Awake()
		{
			_copyButton.onClick.AddListener(delegate
			{
				_productId.text.CopyToClipboard();
			});
		}

		internal void Refresh(IAPDebugProduct product)
		{
			UpdateStatus(product.status);
			SetProductID(product.id);
			SetDetails(product.price + " | " + product.type);
			UpdatePurchaseButton(product);
		}

		internal void UpdateStatus(IAPDebugProduct.Status status)
		{
			_statusAvailable.SetActive(status == IAPDebugProduct.Status.Available);
			_statusMissing.SetActive(status == IAPDebugProduct.Status.Missing);
			_statusBadID.SetActive(status == IAPDebugProduct.Status.BadID);
			_statusOwned.SetActive(status == IAPDebugProduct.Status.Owned);
		}

		public void SetProductID(string text)
		{
			_productId.text = text;
		}

		public void SetDetails(string details)
		{
			_details.text = details;
		}

		internal void UpdatePurchaseButton(IAPDebugProduct product)
		{
			_purchaseButton.interactable = product.hasPurchaseButton;
			_ = _purchaseButton.interactable;
		}
	}
}
